package com.hd.tiyu.yuejian.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.hd.tiyu.yuejian.Adapter.FaTieAdapter;
import com.hd.tiyu.yuejian.JavaBean.FaTie;
import com.hd.tiyu.yuejian.Model.ListsModel;
import com.hd.tiyu.yuejian.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FaTieListActivity extends AppCompatActivity {
    private ImageView back;
    RecyclerView recyclerView;
    private String User_Id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fa_tie_list);
        User_Id=getIntent().getStringExtra("User_Id");
        initViews();
        initEvens();
        initData();
    }

    private void initViews() {
        back=(ImageView)findViewById(R.id.img_fatie_back);
        recyclerView=(RecyclerView) findViewById(R.id.fatielist);
        recyclerView.setLayoutManager(new LinearLayoutManager(FaTieListActivity.this));
    }

    private void initEvens() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void initData() {
        ListsModel listModel=new ListsModel();
        Call<List<FaTie>> call=listModel.getFaTie(User_Id);
        call.enqueue(new Callback<List<FaTie>>() {
            @Override
            public void onResponse(Call<List<FaTie>> call, Response<List<FaTie>> response) {
                List<FaTie> data=response.body();
                recyclerView.setAdapter(new FaTieAdapter(FaTieListActivity.this,data));
            }

            @Override
            public void onFailure(Call<List<FaTie>> call, Throwable t) {
                Toast.makeText(FaTieListActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });

    }
}
